package com.objetdirect.gwt.umldrawer.server.services;

import java.util.Date;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.objetdirect.gwt.umldrawer.server.dao.MessagesDao;
import com.objetdirect.gwt.umldrawer.shared.dto.DeveloperDto;
import com.objetdirect.gwt.umldrawer.shared.dto.MessagesDto;
import com.objetdirect.gwt.umldrawer.shared.services.MessagesService;

@Service("messageService")
public class MessagesServiceImpl implements MessagesService {

	@Autowired
	private MessagesDao messagesDao;

	@PostConstruct
	public void init() throws Exception {
	}

	@PreDestroy
	public void distroy() {
	}

	@Override
	@Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public void sendMessage(String sender, String reciever, String topic,
			String body) throws Exception {
		
		DeveloperDto developer = new DeveloperDto(reciever);
		MessagesDto message = new MessagesDto(sender, topic, new Date(), new Date(), body, 1, developer);
		messagesDao.persist(message);
	}

	@Override
	@Transactional (propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public List<MessagesDto> getMessages(String developerEmail)
			throws Exception {
		
		return null;
	}

}
